// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   register_ok.java

package hr.file;

import com.jspsmart.upload.*;
import include.nseer_cookie.getFileLength;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;

public class register_ok extends HttpServlet
{

	ServletContext application;
	HttpSession session;
	nseer_db_backup1 erp_db;

	public register_ok()
	{
		erp_db = null;
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			getFileLength getFileLength = new getFileLength();
			HttpSession session = request.getSession();
			java.io.PrintWriter out = response.getWriter();
			nseer_db_backup1 hr_db = new nseer_db_backup1(dbApplication);
			SmartUpload mySmartUpload = new SmartUpload();
			mySmartUpload.setCharset("UTF-8");
			if (hr_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String human_ID = request.getParameter("human_ID");
				String file_type = "jpg,gif";
				long d = include.nseer_cookie.getFileLength.getFileLength((String)session.getAttribute("unit_db_name"));
				mySmartUpload.setMaxFileSize(d);
				mySmartUpload.setAllowedFilesList(file_type);
				mySmartUpload.initialize(pageContext);
				try
				{
					mySmartUpload.upload();
					SmartFile myFile = mySmartUpload.getFiles().getFile(0);
					ServletContext context = session.getServletContext();
					String path = context.getRealPath("/");
					String file = (new StringBuilder(String.valueOf(human_ID))).append(myFile.getFileName().substring(myFile.getFileName().length() - 4).toLowerCase()).toString();
					myFile.saveAs((new StringBuilder(String.valueOf(path))).append("hr/human_pictures/").append(file).toString());
					String sql = (new StringBuilder("update hr_file set picture='")).append(file).append("' where human_ID='").append(human_ID).append("'").toString();
					hr_db.executeUpdate(sql);
					response.sendRedirect((new StringBuilder("hr/file/register_choose_attachment.jsp?human_ID=")).append(human_ID).toString());
				}
				catch (Exception ex)
				{
					response.sendRedirect((new StringBuilder("hr/file/register_ok_a.jsp?human_ID=")).append(human_ID).toString());
				}
				hr_db.commit();
				hr_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
